//
//  MQMainViewController.swift
//  MQWeibo
//
//  Created by 毛强 on 15/12/27.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

class MQMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        let tabBar = MQTabBar()
        tabBar.composeButtonClickClouser={[weak self] in
            print("点击➕")
            if self != nil{
                let composeView = MQComposeView()
                composeView.show(self!)
            }
        }

        setValue(tabBar, forKeyPath: "tabBar")
        
        addChildViewControllers()
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func addChildViewControllers() {
        addChildViewController(MQHomeTableViewController(), imgName: "tabbar_home", title: "首页")
        addChildViewController(MQMessageTableViewController(), imgName: "tabbar_message_center", title: "消息")
        addChildViewController(MQDiscoverTableViewController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(MQProfileTableViewController(), imgName: "tabbar_profile", title: "我")
    }
    
    //添加子控制器
    func addChildViewController(childController: UIViewController, imgName:String, title:String) {
        
        childController.tabBarItem = MQTabBarItem()
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(.AlwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)

        let dict = [NSForegroundColorAttributeName: UIColor.orangeColor()]
        childController.tabBarItem.setTitleTextAttributes(dict, forState: UIControlState.Selected)
        
        addChildViewController(MQNavigationController(rootViewController:childController))
    }

}
